<?php $this->load->view('header'); ?>
<?php 
    // echo "<pre>";
    // print_r($singleRecruitment->row_array());
    // echo "</pre>";
    $singleRecruitment = $singleRecruitment->row_array();
    if(count($singleRecruitment)){
        $job_id = $singleRecruitment['job_id'];
        $industry_id = $singleRecruitment['industry_id'];
        $job_related = $singleRecruitment['job_related'];
        $job_name = $singleRecruitment['job_name'];
        $location = $singleRecruitment['location'];
        $job_description = $singleRecruitment['job_description'];
        $job_requirement = $singleRecruitment['job_requirement'];
        $job_benefit = $singleRecruitment['job_benefit'];
        $contact_info = $singleRecruitment['contact_info'];
        $related_job = site_url()."/recruitment/showSingleRecruitment";
        // Đếm số lượt xem 
        $counter = $this->recruitment_model->view_counter($job_id);
    }else{
        $job_id = '';
        $industry_id = '';
        $job_related = '';
        $job_name = '';
        $location = '';
        $job_description = '';
        $job_requirement = '';
        $job_benefit = '';
        $contact_info = '';
        $related_job = '';
        $counter = '';
    }


    $data = $this->recruitment_model->getAllIndustry();
    $data = $data->result_array();
    $name_city = $this->recruitment_model->getNameCity();
    $name_city = $name_city->result();
    



    
?>
<div class="wrap-content">
    <div class="container">
        <div class="row">
            <div style="margin-top:30px"></div>

            <div class="col-lg-12">
                <form method="POST" action="<?php echo site_url('search/job');?>">
                    <div class="frm-search frm-search-freelancer col-lg-5 col-xs-5 col-md-5">
                        <input type="text" class="form-control" name = "job_name" id="exampleInputEmail1" placeholder='"Nhập từ khóa công việc"'>
                    </div> <!-- frm-search -->
                    <div class="col-lg-3 col-md-3 col-xs-3">
                        <select class="form-control" name="industry" id="industry">
                            <option value="0">Chọn ngành nghề</option>
                            <?php 
                                foreach ($data as $value) {
                                    echo '<option value="'.$value["industry_id"].'">'.$value["industry_name"].'</option>';
                                }
                            ?>
                        </select>
                    </div><!-- end of ngành nghề-->
                    <div class="col-lg-3 col-md-3 col-xs-3">
                        <select class="form-control" name="workplace" id="workplace">
                            <option value="0">Chọn địa điểm</option>
                            <?php
                                foreach ($name_city as $value) {
                                    echo "<option value='".$value->location_id."'>".$value->location_name."</option>";
                                }
                                     
                                
                            ?>
                        </select>
                    </div><!-- end of workplace-->
                    <div class="col-lg-1 col-xs-1 col-md-1">
                        <button type="submit" class="icon-lookup" id="btn_submit"></button>
                    </div>
                </form> 
            </div>
            <!-- main -->
            <div class="col-lg-12 col-xs-12 main-job">
                <div style="margin-bottom:20px"></div>
                <div class="col-lg-8 job-detail-left">
                	<div class="job-detail-box">
                		<div class="job-detail-title1">
                			<?php echo $job_name; ?>
                		</div>
                		<div class="job-detail-title2">Mô tả chi tiết công việc</div>
                		<div class="job-detail-content">
                			<ul>
                            <?php 
                                $job_description = explode(".", $job_description);
                                foreach ($job_description as $value) {
                                    if(!empty($value))
                                    echo '<li>'.$value.'</li>';
                                }
                            ?>
                			</ul>
                		</div>

                		<div class="job-detail-title2">Yêu cầu công việc</div>
                		<div class="job-detail-content">
                			<ul>
                            <?php 
                                $job_requirement = explode(".", $job_requirement);
                                foreach ($job_requirement as $value) {
                                    if(!empty($value))
                                    echo '<li>'.$value.'</li>';
                                }
                            ?>
                			</ul>
                		</div>

                		<div class="job-detail-title2">Quyền lợi</div>
                		<div class="job-detail-content">
                			<ul>
            				<?php 
                                $job_benefit = explode(".", $job_benefit);
                                foreach ($job_benefit as $value) {
                                    if(!empty($value))
                                    echo '<li>'.$value.'</li>';
                                }
                            ?>
                			</ul>
                		</div>

                		<div class="job-detail-title2">Thông tin liên hệ</div>
                		<div class="job-detail-content2">
                			<table class="table">
                				<tbody>
                					<tr class="active">
                						<td>Thông tin liên hệ</td>
                						<td><?php if(!empty($singleRecruitment['contact_info']))echo $singleRecruitment['contact_info']; ?></td>
                					</tr>
                					<tr class="success">
                						<td>Email</td>
                						<td><?php if(!empty($singleRecruitment['email'])) echo $singleRecruitment['email']; ?></td>
                					</tr>
                					<tr class="info">
                						<td>Phone</td>
                						<td><?php if(!empty($singleRecruitment['phone'])) echo $singleRecruitment['phone']; ?></td>
                					</tr>
                					<tr class="warning">
                						<td>Website</td>
                						<td><a href="<?php if(!empty($singleRecruitment['website'])) echo $singleRecruitment['website']; ?>"><?php if(!empty($singleRecruitment['website'])) echo $singleRecruitment['website']; ?></a></td>
                					</tr>
                				</tbody>                				
                			</table>
                		</div>
                	</div>
                	<div class="btn-recruitment col-lg-12">
                    	<div class="col-lg-8 col-xs-8"><button class="btn btn-lg btn-primary" data-toggle="tooltip" data-placement="top" title="Chức năng đang hoàn thiện">Nộp hồ sơ</button></div>
                    	<div class="col-lg-4 col-xs-4">Số lượt xem : <?php echo $counter;?></div>
                    </div>
                	<div class="job-detail-apply"></div>
                </div><!-- end job-detail-left-->
                
                <div class="col-lg-4">
                	<div class="right-1 col-lg-12">
                        <div class="job-detail-description1">
                            <div class="job-detail-item">
                                <div class="job_detail_title_count">số lượng tuyển</div>
                                <div class="job_detail_text"><?php if(!empty($singleRecruitment['num_recruit'])) echo $singleRecruitment['num_recruit'];?></div>
                            </div>
                            <div class="job-detail-item2">
                                <div class="job_detail_title_location">nơi làm việc</div>
                                <div class="job_detail_text"><?php if(!empty($singleRecruitment['workplace'])) echo $singleRecruitment['workplace'];?></div>
                            </div>
                            <div class="job-detail-item">
                                <div class="job_detail_title_dateline">hạn nộp hồ sơ</div>
                                <div class="job_detail_text"><?php if(!empty($singleRecruitment['expired_at'])) echo $singleRecruitment['expired_at'];?></div>
                            </div>
                            <div class="job-detail-item2">
                                <div class="job_detail_title_work">loại hình công việc</div>
                                <div class="job_detail_text"><?php if(!empty($singleRecruitment['type_of_job'])) echo $singleRecruitment['type_of_job'];?></div> 
                            </div>                           
                        </div><!-- end job-detail-description1 -->
                		
                    	<div class="job-detail-description">
                            <div class="job_detail_news_lq">tin liên quan</div>
                            <?php
                                if(!empty($job_related))
                                foreach (explode(",", $job_related) as $value) {
                                    $temp = $this->recruitment_model->getJobRelated($value);
                                    $temp = $temp->row_array();
                            ?>
                                <div class="job_lq">
                                <a href="<?php echo $related_job.'/'.$value.'/'.$temp['industry_id'];?>"><?php echo $temp['job_name'];?></a>
                                <br><?php $t = $this->recruitment_model->getNameCityById($temp['location']);
                                        echo $t->location_name;?>
                                </div>
                            <?php        
                                }
                            ?>
                        </div><!-- end job related -->		                	   
                    </div> 
                </div>               
            </div>
        </div> <!-- end row content -->
    </div>
</div> <!-- wrap-content -->
<script>
   $(function () { $("[data-toggle='tooltip']").tooltip(); });
</script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#btn_submit").click(function(e){
            var industry = $("#industry").val();
            var workplace = $("#workplace").val();
            if(industry == 0 && workplace == 0){
                e.preventDefault();
                $("#myModal").modal('show');
            }
        });
        
    });
</script>

<div class="modal fade" id="myModal">
    <div id="show_result"></div>
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Notification</h4>
            </div>
            <div class="modal-body">
                <h3><center><strong>Please choose at least a Industry or Workplace</strong></center></h3>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('footer'); ?>